package com.wang.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wang.auth.mapper.ProcessTypeMapper;
import com.wang.auth.service.ProcessTemplateService;
import com.wang.auth.service.ProcessTypeService;
import com.wang.model.process.ProcessTemplate;
import com.wang.model.process.ProcessType;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 审批类型 服务实现类
 * </p>
 *
 * @author wang
 * @since 2023-04-17
 */
@Service
public class ProcessTypeServiceImpl extends ServiceImpl<ProcessTypeMapper, ProcessType> implements ProcessTypeService {

    @Resource
    private ProcessTemplateService processTemplateService;
    @Override
    public List<ProcessType> findProcessType() {
        //查询审批分类集合
        List<ProcessType> list = this.list();
        //根据分类id查询分类中的审批模板集合
        for (ProcessType processType : list) {
            LambdaQueryWrapper<ProcessTemplate> processTemplateLambdaQueryWrapper = new LambdaQueryWrapper<>();
            processTemplateLambdaQueryWrapper.eq(ProcessTemplate::getProcessTypeId,processType.getId());
            List<ProcessTemplate> processTemplateList = processTemplateService.list(processTemplateLambdaQueryWrapper);
            //将每个审批模板按照它对应的审批分类封装
            processType.setProcessTemplateList(processTemplateList);
        }
        return list;
    }
}
